<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function date() {
        var myDate = new Date()
        var y = myDate.getFullYear()
        var m = zeroFill(myDate.getMonth() + 1)
        var d = zeroFill(myDate.getDate())
        var h = zeroFill(myDate.getHours())
        var M = zeroFill(myDate.getMinutes())
        var s = zeroFill(myDate.getSeconds())
        var str = `${y}-${m}-${d}  ${h}:${M}:${s}`
        return str
      }
      var res = date()
      console.log(res)

      function zeroFill(n) {
        return n < 10 ? '0' + n : n
      }
    </script>
  </body>
</html>
